package org.product.controller;

import com.google.gson.Gson;
import org.product.dao.ProductDao;
import org.product.entity.Product;
import org.product.factory.DaoFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;


@WebServlet("/api/queryAll.do")
public class QueryAllServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ProductDao productDao = DaoFactory.getProductDaoInstance() ;

        List<Product> list = productDao.selectAll() ;

        // req.setAttribute("list",list);
        resp.setContentType("application/json;charset=utf-8");

        PrintWriter out = resp.getWriter() ;
        out.print(new Gson().toJson(successJson(list)));
        out.flush();
        out.close();
    }
}
